package com.xja.controller;

import com.xja.WebStart;
import com.xja.entity.Users;
import com.xja.service.UsersService;
import org.apache.dubbo.config.annotation.Reference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

/**
 * @author 周广瑞
 * @date 2022/4/14 11:13
 */
@Controller
@RequestMapping("user")
public class UsersController {
    private Logger logger = LoggerFactory.getLogger(WebStart.class);
    @Reference(url = "dubbo://localhost:20880")
    private UsersService usersService;

    @RequestMapping("login")
    public String login( Users users,HttpSession session){
        logger.info("登录验证。。。。。。");

        Users login = usersService.selectUser(users.getLoginname());
//        System.out.println(users+"sssssssssssss接收前端用户名");


//        if (login.getId()==1 && login.getLoginname()==users.getLoginname() && login.getLoginpwd()==users.getLoginpwd()){
//            System.out.println("跳转管理员页面");
//            return "redirect:/static/food_list.html";
//        }
        if ( login==null || !login.getLoginpwd().equals(users.getLoginpwd())
                || !login.getLoginname().equals(users.getLoginname())){
            return "redirect:/login.html";
        }
//        System.out.println(login+".........loin");
        session.setAttribute("login",login);
        return "redirect:/food/foodList";

    }
}
